package com.example.wechatbot.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class MessageDispatcher {
    @Autowired
    private PersonalInfoProcessor personalInfoProcessor;
    @Autowired
    private HobbyProcessor hobbyProcessor;
    @Autowired
    private PhoneProcessor phoneProcessor;
    @Autowired
    private DepartmentProcessor departmentProcessor;
    @Autowired
    private ChannelProcessor channelProcessor;
    @Autowired
    private PerformanceProcessor performanceProcessor;

    private Map<String, Object> categoryProcessorMap = new HashMap<>();

    public MessageDispatcher() {
        categoryProcessorMap.put("个人信息", personalInfoProcessor);
        categoryProcessorMap.put("爱好", hobbyProcessor);
        categoryProcessorMap.put("电话", phoneProcessor);
        categoryProcessorMap.put("部门", departmentProcessor);
        categoryProcessorMap.put("渠道", channelProcessor);
        categoryProcessorMap.put("绩效", performanceProcessor);
    }

    public String dispatch(String questioner, String question) {
        // 模拟调用豆包AI分解问题
        String category = "个人信息"; // 假设分解出的类别为个人信息
        String condition = "张三"; // 假设分解出的条件为张三

        try {
            Object processor = categoryProcessorMap.get(category);
            if (processor != null) {
                String answer = ((Processor) processor).process(condition);
                // 记录提问和回答过程
                // 实现记录逻辑
                return answer;
            } else {
                return "未找到对应的处理类";
            }
        } catch (Exception e) {
            // 记录错误信息
            // 实现错误记录逻辑
            return "处理问题时发生错误：" + e.getMessage();
        }
    }
}


interface Processor {
    String process(String condition);
}
